package leetcode;

/**
 * 题目：温度趋势
 * 链接：https://leetcode.cn/problems/temperature-trend/description/
 */
public class TemperatureTrend {
    public static void main(String[] args) {
        System.out.println(temperatureTrend(new int[]{21,18,18,18,31}, new int[]{34,32,16,16,17}));
//        System.out.println(temperatureTrend(new int[]{5,10,16,-6,15,11,3}, new int[]{16,22,23,23,25,3,-16}));
    }
    // 本质求两地趋势一样的最长发连续天数
    public static int temperatureTrend(int[] temperatureA, int[] temperatureB) {
        int today = temperatureA.length;
        int max = 0;
        int cur = 0;
        for (int i = 1; i < today; i++) {
            int ta = getTrend(temperatureA[i], temperatureA[i-1]);
            int tb = getTrend(temperatureB[i], temperatureB[i-1]);
            if (ta == tb) {
                cur++;
            } else {
                cur = 0;
            }
            max = Math.max(max, cur);
        }
        return max;
    }

    public static int getTrend(int ta, int tb) {
        if (ta == tb) {
            return 0;
        }
        return ta > tb ? 1 : -1;
    }
}
